//
// Created by 成飞 on 2024/3/21.
//

#include "config_data.h"
#include "config/conf.hpp"

#include <string>
#include <sstream>
#include <thread>
namespace conf{
    ConfData data;

    using std::stoi;
    using std::thread;

    void initConfData(){
        auto env = Env::instance();
        data.db.store_path = env.get_section_attr("db", "store_path");
        data.db.vstore_path = data.db.store_path + "/vstore";
        data.db.lsm_path = data.db.store_path + "/lsm";
        data.db.meta_path = data.db.store_path + "/meta";
        data.db.scan_thread_num = stoi(env.get_section_attr("db", "scan_thread_num"));
        if (data.db.scan_thread_num == 0)
            data.db.scan_thread_num = thread::hardware_concurrency();

        data.value_store.buffer_num = stoi(env.get_section_attr("value_store", "buffer_num"));
        data.value_store.buffer_size = Util::convert_to_byte_number(env.get_section_attr("value_store", "buffer_size"));
        std::istringstream(env.get_section_attr("value_store", "garbage_tolerance")) >> data.value_store.garbage_tolerance;

        data.lsm.db_engine = env.get_section_attr("lsm", "db_engine");
    }
}
